from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-25 14:10:35.469861
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 25, Apr, 2021
Time: 14:10:40
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.7588
Nobs: 272.000 HQIC: -48.4729
Log likelihood: 3273.89 FPE: 5.50301e-22
AIC: -48.9519 Det(Omega_mle): 3.97630e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.427972 0.121754 3.515 0.000
L1.Burgenland 0.085510 0.060599 1.411 0.158
L1.Kärnten -0.221156 0.053316 -4.148 0.000
L1.Niederösterreich 0.100397 0.130027 0.772 0.440
L1.Oberösterreich 0.219671 0.124924 1.758 0.079
L1.Salzburg 0.264351 0.068973 3.833 0.000
L1.Steiermark 0.112872 0.087725 1.287 0.198
L1.Tirol 0.118647 0.060602 1.958 0.050
L1.Vorarlberg -0.039040 0.055730 -0.701 0.484
L1.Wien -0.059905 0.112714 -0.531 0.595
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.464836 0.141523 3.285 0.001
L1.Burgenland 0.006297 0.070438 0.089 0.929
L1.Kärnten 0.331515 0.061973 5.349 0.000
L1.Niederösterreich 0.092921 0.151139 0.615 0.539
L1.Oberösterreich -0.062132 0.145207 -0.428 0.669
L1.Salzburg 0.219436 0.080172 2.737 0.006
L1.Steiermark 0.096935 0.101968 0.951 0.342
L1.Tirol 0.137551 0.070442 1.953 0.051
L1.Vorarlberg 0.150833 0.064778 2.328 0.020
L1.Wien -0.427547 0.131014 -3.263 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.276963 0.061859 4.477 0.000
L1.Burgenland 0.098011 0.030788 3.183 0.001
L1.Kärnten -0.014439 0.027088 -0.533 0.594
L1.Niederösterreich 0.079834 0.066063 1.208 0.227
L1.Oberösterreich 0.285012 0.063470 4.491 0.000
L1.Salzburg 0.018714 0.035043 0.534 0.593
L1.Steiermark -0.003757 0.044570 -0.084 0.933
L1.Tirol 0.071827 0.030790 2.333 0.020
L1.Vorarlberg 0.077646 0.028314 2.742 0.006
L1.Wien 0.113087 0.057266 1.975 0.048
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.215482 0.059270 3.636 0.000
L1.Burgenland 0.024724 0.029500 0.838 0.402
L1.Kärnten 0.009529 0.025954 0.367 0.714
L1.Niederösterreich 0.052259 0.063298 0.826 0.409
L1.Oberösterreich 0.398095 0.060813 6.546 0.000
L1.Salzburg 0.078829 0.033576 2.348 0.019
L1.Steiermark 0.130154 0.042705 3.048 0.002
L1.Tirol 0.049487 0.029501 1.677 0.093
L1.Vorarlberg 0.082512 0.027129 3.041 0.002
L1.Wien -0.041200 0.054869 -0.751 0.453
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.489423 0.116128 4.215 0.000
L1.Burgenland 0.097364 0.057799 1.685 0.092
L1.Kärnten 0.010163 0.050852 0.200 0.842
L1.Niederösterreich -0.000745 0.124018 -0.006 0.995
L1.Oberösterreich 0.125679 0.119151 1.055 0.292
L1.Salzburg 0.055571 0.065785 0.845 0.398
L1.Steiermark 0.067744 0.083671 0.810 0.418
L1.Tirol 0.207870 0.057801 3.596 0.000
L1.Vorarlberg 0.033457 0.053154 0.629 0.529
L1.Wien -0.079325 0.107505 -0.738 0.461
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205987 0.091828 2.243 0.025
L1.Burgenland -0.012666 0.045704 -0.277 0.782
L1.Kärnten -0.008097 0.040211 -0.201 0.840
L1.Niederösterreich -0.011806 0.098067 -0.120 0.904
L1.Oberösterreich 0.417381 0.094218 4.430 0.000
L1.Salzburg 0.013052 0.052020 0.251 0.802
L1.Steiermark -0.029162 0.066162 -0.441 0.659
L1.Tirol 0.162480 0.045706 3.555 0.000
L1.Vorarlberg 0.056617 0.042032 1.347 0.178
L1.Wien 0.211885 0.085009 2.492 0.013
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.231142 0.111319 2.076 0.038
L1.Burgenland 0.018832 0.055405 0.340 0.734
L1.Kärnten -0.070374 0.048746 -1.444 0.149
L1.Niederösterreich -0.073481 0.118883 -0.618 0.537
L1.Oberösterreich 0.024122 0.114217 0.211 0.833
L1.Salzburg 0.081298 0.063061 1.289 0.197
L1.Steiermark 0.329412 0.080206 4.107 0.000
L1.Tirol 0.460812 0.055408 8.317 0.000
L1.Vorarlberg 0.147373 0.050953 2.892 0.004
L1.Wien -0.145433 0.103053 -1.411 0.158
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200294 0.133192 1.504 0.133
L1.Burgenland 0.039627 0.066292 0.598 0.550
L1.Kärnten -0.077082 0.058325 -1.322 0.186
L1.Niederösterreich 0.102592 0.142243 0.721 0.471
L1.Oberösterreich 0.013606 0.136659 0.100 0.921
L1.Salzburg 0.196143 0.075452 2.600 0.009
L1.Steiermark 0.130620 0.095966 1.361 0.173
L1.Tirol 0.057484 0.066295 0.867 0.386
L1.Vorarlberg 0.107593 0.060965 1.765 0.078
L1.Wien 0.237011 0.123302 1.922 0.055
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.547920 0.072679 7.539 0.000
L1.Burgenland -0.018480 0.036173 -0.511 0.609
L1.Kärnten -0.017505 0.031826 -0.550 0.582
L1.Niederösterreich 0.083819 0.077617 1.080 0.280
L1.Oberösterreich 0.307839 0.074571 4.128 0.000
L1.Salzburg 0.015843 0.041172 0.385 0.700
L1.Steiermark -0.043560 0.052365 -0.832 0.405
L1.Tirol 0.079835 0.036175 2.207 0.027
L1.Vorarlberg 0.110100 0.033267 3.310 0.001
L1.Wien -0.060621 0.067282 -0.901 0.368
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.159356 0.102461 0.167557 0.221405 0.077444 0.087815 0.003871 0.160132
Kärnten 0.159356 1.000000 0.054555 0.208857 0.182640 -0.062845 0.172349 0.022497 0.303770
Niederösterreich 0.102461 0.054555 1.000000 0.241570 0.084736 0.323741 0.146504 0.018656 0.301328
Oberösterreich 0.167557 0.208857 0.241570 1.000000 0.304870 0.260177 0.093951 0.062282 0.132294
Salzburg 0.221405 0.182640 0.084736 0.304870 1.000000 0.152340 0.060605 0.090400 0.014489
Steiermark 0.077444 -0.062845 0.323741 0.260177 0.152340 1.000000 0.099052 0.099231 -0.100428
Tirol 0.087815 0.172349 0.146504 0.093951 0.060605 0.099052 1.000000 0.153996 0.146213
Vorarlberg 0.003871 0.022497 0.018656 0.062282 0.090400 0.099231 0.153996 1.000000 -0.006144
Wien 0.160132 0.303770 0.301328 0.132294 0.014489 -0.100428 0.146213 -0.006144 1.000000